/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.ws.client.program;

import junit.framework.TestCase;
import net.bioteam.appweb.TestConfig;
import net.bioteam.appweb.model.Program;
import net.bioteam.appweb.model.ProgramBuilder;
import net.bioteam.appweb.submit.ProgramValueBean;
import net.bioteam.appweb.user.User;
import net.bioteam.appweb.ws.WsClient;

public class EmbossHmmer extends TestCase
{

	public EmbossHmmer()
	{
		super();
	}

	public EmbossHmmer(String name)
	{
		super(name);
	}

	public WsClient client;

	protected void setUp() throws Exception
	{
		TestConfig.init();
		User user = new User();
		user.setName(TestConfig.username);
		user.setPassword(TestConfig.password);
		client = new WsClient(user, TestConfig.serviceURL, null);
	}

	public static void main(String args[]) throws Exception
	{
		// EmbossHmmer test=new EmbossHmmer();
		// test.setUp();
		// Method[] mss=test.getClass().getMethods();
		// for (Method ms: mss)
		// {
		// if (ms.getName().startsWith("test"))
		// {
		// ms.invoke(test);
		// //break;
		// }
		// }

		EmbossHmmer test = new EmbossHmmer("testPfam_scan");
		junit.textui.TestRunner.run(test);
	}

	public void testPfam_scan() throws Exception
	{
		String program = "pfam_scan";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("infile", "inputs/globins.fasta");
		bean.setValue("fast", "1");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testEhmmfetch() throws Exception
	{
		String program = "ehmmfetch";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("database", "$HMMERDB/Pfam_ls");
		bean.setValue("name", "1-cysPrx_C");
		// bean.setValue("a", "10");
		// bean.setValue("outfile", "hmmsearch.txt");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testEhmmpfam1() throws Exception
	{
		String program = "ehmmpfam";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("hmmfile", "$HMMERDB/Pfam_ls");
		bean.setValue("seqfile", "inputs/7LES_DROME");
		// bean.setValue("a", "10");
		// bean.setValue("outfile", "hmmsearch.txt");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testEhmmpfam() throws Exception
	{
		String program = "ehmmpfam";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("hmmfile", "inputs/globino.hmm");
		bean.setValue("seqfile", "inputs/Artemia.fa");
		bean.setValue("a", "10");
		// bean.setValue("outfile", "hmmsearch.txt");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testEhmmsearch() throws Exception
	{
		String program = "ehmmsearch";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("hmmfile", "inputs/globino.hmm");
		bean.setValue("seqfile", "inputs/Artemia.fa");
		bean.setValue("a", "100");
		bean.setValue("outfile", "hmmsearch.txt");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testEhmmemit() throws Exception
	{
		String program = "ehmmemit";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("hmmfile", "inputs/globino.hmm");
		// bean.setValue("c", "1");
		bean.setValue("nseq", "11");
		bean.setValue("o", "hmm.emmit");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testEhmmconvert() throws Exception
	{
		String program = "ehmmconvert";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("oldhmmfile", "inputs/globino.hmm");
		bean.setValue("format", "G");
		bean.setValue("newhmmfile", "globinnew.hmm");
		// bean.setValue("strategy", "D");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testEhmmBuild() throws Exception
	{
		String program = "ehmmbuild";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("alignfile", "inputs/globins50.msf");
		bean.setValue("nhmm", "globins50");
		bean.setValue("hmmfile", "globin.hmm");
		bean.setValue("strategy", "D");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testEhmmalign() throws Exception
	{
		String program = "ehmmalign";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("hmmfile", "inputs/globino.hmm");
		bean.setValue("seqfile", "inputs/globins630.fa");
		bean.setValue("o", "globin630.alifn");
		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testEhmmcalibrate() throws Exception
	{
		String program = "ehmmcalibrate";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("hmmfilein", "inputs/globin.hmm");
		bean.setValue("hmmfileout", "globino.hmm");
		bean.setValue("seed", "1");
		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	protected void postJobProcess(String ret[])
	{
		String jobid = ret[0];
		TestConfig.logger.info("job id is " + jobid);
		TestConfig.logger.info("cmdline is " + ret[2]);
	}

}
